//
//  MyGreeterTest.swift
//  Re-mygreetingsTests
//
//  Created by Jia Chen on 2022/8/9.
//

import XCTest
// 可以使用Re_mygreetings中public的类
@testable import Re_mygreetings

class MyGreeterTest: XCTestCase {

    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }

    func testExample() throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let gr = MyGreeterClient()
        
        // 这里测试的话用时间戳来测试会好一点
        // 6 -> Good morning
        // 12 -> Good afternoon
        // 18 -> Good evening
        // -1 -> error
        // 25 -> error
        // 7 -> Good morning
        // 13 -> Good afternoon
        // 5 -> Good evening
        // 19 -> Good evening
        // 24 -> error
        // 0 -> Good evening
        print("*********************START CASES********************")
        /*
        XCTAssert(testModule(h: 6) == "Good morning", "success")
        XCTAssert(testModule(h: 12) == "Good afternoon", "success")
        XCTAssert(testModule(h: 18) == "Good evening", "success")
        XCTAssert(testModule(h: -1) == "error", "success")
        XCTAssert(testModule(h: 25) == "error", "success")
        XCTAssert(testModule(h: 7) == "Good morning", "success")
        XCTAssert(testModule(h: 13) == "Good afternoon", "success")
        XCTAssert(testModule(h: 5) == "Good evening", "success")
        XCTAssert(testModule(h: 19) == "Good evening", "success")
        XCTAssert(testModule(h: 24) == "error", "success")
        XCTAssert(testModule(h: 0) == "Good evening", "success")
         */
        // 直接调用
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 6) == "Good morning", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 12) == "Good afternoon", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 18) == "Good evening", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: -1) == "error", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 25) == "error", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 7) == "Good morning", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 13) == "Good afternoon", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 5) == "Good evening", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 19) == "Good evening", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 24) == "error", "success")
        XCTAssert(MyGreeterClient.triggerMyGreets(h: 0) == "Good evening", "success")
        print("*********************All CASES PASS********************")
        print("*********************END CASES********************")
               
    }
    
    func testModule(h: Int) -> String {
        guard h >= 0, h < 24 else {
            return "error"
        }
        
        if h >= 6 && h < 12 {
            return "Good morning"
        } else if h >= 12 && h < 18 {
            return "Good afternoon"
        } else {
            return "Good evening"
        }
    }
    
    func test_aysncLoad() {
//        let exp = exception(for)
    }

    func testPerformanceExample() throws {
        // This is an example of a performance test case.
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }

}
